package com.neo.debade.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.context.WebApplicationContext;

@SuppressWarnings({ "serial" })
public class BaseServlet extends HttpServlet {
	
	protected Log logger = LogFactory.getLog(getClass());

	/**
	 * @param requset
	 * @param response
	 * @param data
	 */
	protected void print(HttpServletResponse response, String data) {
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter out = null;
		try {
			out = response.getWriter();
			out.print(data);
		} catch (IOException e) {
			e.printStackTrace();
			// out.print("{'state':'error','message':" + e.getMessage() + "}");
		} finally {
			if (out != null) {
				out.flush();
				out.close();
			}
		}
	}
	
	protected WebApplicationContext getWebApplicationContext() {
		return (WebApplicationContext) getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
	}
}
